require "Common/functions"

EffectFunctions = {};
local this = EffectFunctions;

function EffectFunctions.rotateOffset(offset, flip, outVec)
    --logMy("rotateOffset", offset);
    local offsetPos = offset;
	--修正到相机40度  之前是30度
    local offsetY = Mathf.Cos(Mathf.PI/6/3*4) * offsetPos[2];
    local offsetZ = Mathf.Sin(Mathf.PI/6/3*4) * offsetPos[2];
    local offsetX = tonumber(offsetPos[1]);
    if flip then
        offsetX = -offsetX;
    end

    if outVec then 
        outVec.x = offsetX
        outVec.y = offsetY
        outVec.z = offsetZ
        return outVec
    else
        return Vector3(offsetX, offsetY, offsetZ);
    end
end

function EffectFunctions.calcFollowPositionV2(followInfo)
    if not followInfo then
        return
    end
    if not followInfo.position then
        followInfo.position = Vector3(0, 0, 0);
    end
    local tempRotatedOffset = followInfo.rotatedOffset;
    -- print("==================EffectFunctions.calcFollowPositionV2(followInfo)", type(followInfo.position) )
    -- Util.Lua_CalcFollowPositionV2(followInfo.followBone, followInfo.followBoneSpineTrans, followInfo.followTrans, followInfo.position,
    --         tempRotatedOffset.x, tempRotatedOffset.y, tempRotatedOffset.z)

    if followInfo and followInfo.position  then
        local pos = Util.Lua_CalcFollowTargetPosition(followInfo.followBone, followInfo.followBoneSpineTrans, followInfo.followTrans)
        -- print("pos:", type(pos), pos)
        followInfo.position.x = pos.x + tempRotatedOffset.x
        followInfo.position.y = pos.y + tempRotatedOffset.y
        followInfo.position.z = pos.z + tempRotatedOffset.z
    end
end

function EffectFunctions.getFollowInfo(followTrans, offset, followBone, followBoneSpineTrans)

    local followInfo = {};
    followInfo.followTrans = followTrans;
    followInfo.offset = offset;
    followInfo.followBone = followBone;
    followInfo.followBoneSpineTrans = followBoneSpineTrans;

    return followInfo;
end


--t [0, 1], d 为从0到最高点再到0
function EffectFunctions.calcYByGravity(t)
    t = t * 1.01 * 2 - 1.01;  -- 0.5 * gt * t + 5 = 0  ---> -1.01, 1.01
    local d = -9.8 * 0.5 * t * t + 5;
    return d;
end


function EffectFunctions.calcY(t)
    --y = -x^2 + 1
    t = t * 2 - 1;
    local d = 1 - t * t;
    return d;
end
